<template>
	<view class="orders-box">
		<TopBar :indexflag="true" :combakflag="false" :lang="true" :bottom="true" :title="$t('Order')"
			:barstyle="colortopic()"></TopBar>
		<u-sticky>
			<view class="topnav">
				<view :class="tabs_index==index?'item acitem':'item'" v-for="(item,index) in tabs" :key="index"
					@click="changeTab(index)">
					<view class="text">{{$t(item.name)}}</view>
					<!-- <view :class="tabs_index==index?'line acline':'line'"></view> -->
				</view>
			</view>
		</u-sticky>
		<view class="order-content">
			<scroll-view scroll-y="true" @scrolltolower="scrolldata" style="height:100%;width:100%;position: relative;box-sizing: border-box;">
				<view class="" v-if="!orderList.length" style="height:200rpx"></view>
				<u-empty v-if="orderList.length==0 && !loadshow" mode="order" iconSize="100" textSize="14"
					:text="$t('OrderEmpty')" >
				</u-empty>
				<view class="list" v-if="orderList.length" :style="{direction: i18nLocale=='ug'?'rtl':''}"
					v-for="(item,index) in orderList" :key="item.id">
					<!-- <view class="">{{item.order.out_trade_no}}</view> -->
					<view class="time">
						<text>{{$t('TimePlaced')}} : </text>
						<view class="" style="direction: ltr;">{{item.updated_at?item.updated_at:''}}</view>
					</view>
					<view class="order-item">
						<view class="item" v-for="(subitem,sub_index) in item.items" :key="sub_index">
							<view class="left">
								<view class="name">{{i18nLocale=='ug'?subitem.ug_name:subitem.cn_name}}</view>
							</view>
							<view class="right">
								<view class="number">X{{subitem.qty}}</view>
								<view class="price">￥{{subitem.price}}</view>
							</view>
						</view>
						<view class="totalprice-box">
							<text>{{$t('TotalPrice')}}</text>
							<text class="totalprice">￥{{item.fee}}</text>
						</view>
						<view class="totalprice-box">
							<text>{{$t('PayTitle')}}</text>
							<text class="" v-if="item.payment_status==1">{{$t('PaidOk')}}</text>
							<text class="" v-if="item.payment_status==0">{{$t('ToBepaid')}}</text>
						</view>
					</view>
				</view>
				<view class="" v-if="to==total" style="height:200rpx;"  ></view>
			</scroll-view>
			<Loading :show="loadshow" iconName="circle" bgZindex="99" bgColor=""  :text="$t('Loading')"></Loading>
			<Loading :show="tabloadshow" bgZindex="99" iconName="circle-round" :showText="false"></Loading>
		</view>
	</view>
</template>

<script>
	import {
		getorders,
	} from '@/api/all.js';
	export default {
		data() {
			return {
				tabs: [{
						name: 'AllOrders',
					},
					{
						name: 'Processing',
					},
					{
						name: 'Finish'
					}
				],
				tabs_index: 0,
				orderList: [],
				pageSize: 6,
				page: 1,
				total: 0,
				to: 1,
				tabloadshow: false,
				loadshow: false,

			}
		},
		computed: {
			i18nLocale() {
				return this.$i18n.locale;
			},
		},
		mounted() {
			if (this.$store.state.usertoken) {
				this.scrolldata();
			}
		},

		methods: {
			getOrder(type) {
				let that = this;
				getorders({
					per_page: that.pageSize,
					page: that.page,
					status: type
				}).then((res) => {
					if (res.code == 200) {
						let data = res.body;
						console.log(data, '+++++')
						that.total = data.total;
						that.to = data.to;
						that.page++;
						let mydata = that.orderList.concat(data.data);
						that.orderList = mydata;
						that.tabloadshow = false;
						that.loadshow = false;
					}

				})
			},
			scrolldata() {
				if (this.to != this.total) {
					this.loadshow = true;
					this.getOrder('');
				} else {

				}
			},
			changeTab(index) {
				this.tabs_index = index;
				this.page = 1;
				this.total = 0;
				this.to = 1;
				this.orderList = [];
				this.tabloadshow = true;
				if (index == 0) {
					this.getOrder('');
				} else if (index == 1) {
					this.getOrder(0);
				} else {
					this.getOrder(4);
				}

			},
			//付款
			changePay(id) {
				uni.navigateTo({
					url: '/pages/order/paypage?id=' + id
				})
			},
			changeOrder(item) {
				console.log(item, '+++')
				if (item.status == 0 && item.payment_status == 1) {
					uni.navigateTo({
						url: '/pages/order/orderdatail?id=' + item.id
					})
				}
			},
			changeAppraise() {
				uni.navigateTo({
					url: '/pages/order/appraise'
				})
			}
		}
	}
</script>

<style lang="scss" scoped>
	.orders-box {
		width: 100%;
		height: 100%;

		.topnav {
			width: 100%;
			display: flex;
			align-items: center;
			justify-content: space-around;
			background-color: $uni-bg-color-box;
			box-sizing: border-box;
			padding: 0rpx 20rpx;
			font-size: $uni-font-size-base;

			.item {
				width: 30%;
				display: flex;
				align-items: center;
				justify-content: center;
				padding: 20rpx 0rpx;
			}

			.acitem {
				color: $uni-color-topic;
			}
		}

		.order-content {
			width: 100%;
			height: calc(100% - 320rpx);
			display: flex;
			flex-direction: column;
			position: relative;
			box-sizing: border-box;
			.list {
				width: 100%;
				// height:100%;
				height: clac;
				background: #FFFFFF;
				box-shadow: $uni-bg-shadow;
				border-radius: $uni-border-radius-lg;
				margin-top: 20rpx;
				display: flex;
				flex-direction: column;
				align-items: center;
				padding: 20rpx 40rpx;
				box-sizing: border-box;
				position: relative;

				.time {
					width: 100%;
					height: 80rpx;
					display: flex;
					align-items: center;
					justify-content: space-between;
					font-size: 28rpx;
					color: #000;

					text {
						color: #808080;
					}

					image {
						width: 80rpx;
						height: 80rpx;
					}
				}

				.order-item {
					width: 100%;
					display: flex;
					flex-direction: column;

					.item {
						width: 100%;
						display: flex;
						align-items: center;
						justify-content: space-between;
						padding: 20rpx 0rpx;

						.left {
							display: flex;
							align-items: center;

							image {
								width: 120rpx;
								height: 120rpx;
								border-radius: 20rpx;
							}

							.name {
								color: $uni-color-title;
								font-size: $uni-font-size-base;
								// padding: 0rpx 30rpx;
							}
						}

						.right {
							display: flex;
							align-items: center;

							.price {
								color: $uni-color-topic;
								font-size: $uni-font-size-base;
								padding: 0rpx 30rpx;
							}

							.number {
								color: $uni-text-color-grey;
								font-size: $uni-font-size-sm1;
								padding: 0rpx 30rpx;
							}

						}

					}

					.totalprice-box {
						display: flex;
						justify-content: space-between;
						// justify-content: center;
						align-items: center;
						font-size: 32rpx;
						padding: 10rpx 20rpx;

						.totalprice {
							color: #f4464b;
							font-size: 32rpx;
						}
					}

					.button {
						background-color: $uni-color-topic;
						border-radius: $uni-border-radius-lg;
						padding: 20rpx 80rpx;
						margin: 0 auto;
						color: #fff;
					}


				}

			}


		}
	}
</style>